package il.ac.tau.cvws.scrabblesidekick.shared.util.math;

public class Point
{
	public double x;
	public double y;
	public double z;
	
	public Point(double x, double y)
	{
		this(x, y, 0.0);
	}
	
	public Point(double x, double y, double z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public double getX()
	{
		return x;
	}

	public void setX(double x)
	{
		this.x = x;
	}

	public double getY()
	{
		return y;
	}

	public void setY(double y)
	{
		this.y = y;
	}

	public double getZ()
	{
		return z;
	}

	public void setZ(double z)
	{
		this.z = z;
	}
	
	public Point add(Vector v)
	{
		return new Point(x + v.getX(), y + v.getY(), z + v.getZ());
	}
	
	public Vector subtract(Point v)
	{
		return new Vector(v, this);
	}
	
	public double dist(Point p)
	{
		return new Vector(this, p).length();
	}
	
	public Point interpolate(Point other, double ratio)
	{
		double px = ratio * x + (1 - ratio) * other.x;
		double py = ratio * y + (1 - ratio) * other.y;
		double pz = ratio * z + (1 - ratio) * other.z;
		
		return new Point(px, py, pz);
	}
	
	@Override
	public boolean equals(Object o)
	{
		if ((o == null) || !(o instanceof Point))
		{
			return false;
		}
		
		Point p = (Point)o;
		
		return (x == p.x) && (y == p.y) && (z == p.z); 
	}
	
	@Override
	public int hashCode()
	{
		return Double.valueOf(x + y + z).hashCode();
	}
	
	@Override
	public String toString()
	{
		return "(" + x + ", " + y + ", " + z + ")";
	}
	
	@Override
	public Point clone()
	{
		return new Point(x, y, z);
	}
}
